package xyz.icxl.kotlion.ext.binding

import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.annotation.IdRes
import androidx.databinding.BindingAdapter
import androidx.databinding.ObservableField
import xyz.icxl.kotlion.ext.ImageLoaderHelper


/**
 * 加载资源文件图片
 */
@BindingAdapter("ext_load")
fun ImageView.load(@DrawableRes id: Int?) {
    ImageLoaderHelper.load(this, id)
}

/**
 * 根据地址加载图片
 */
@BindingAdapter("ext_load")
fun ImageView.load(url: String?) {
    if (url != null && !url.isNullOrEmpty())
        ImageLoaderHelper.load(this, url)
}

/**
 * 根据地址加载图片
 */
@BindingAdapter("ext_load")
fun ImageView.load(url: ObservableField<String>?) {
    if (url != null && !url.get().isNullOrEmpty())
        ImageLoaderHelper.load(this, url.get())
}

